package com.xu.consumer.controller;

import com.xu.consumer.service.QRcodeService;
import com.xu.utils.QRCodeUtil;
import io.swagger.annotations.Api;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.image.BufferedImage;
import java.io.IOException;

/**
 * @author 徐老板
 * @date 2020/3/31   13:28
 */
@Api(value = "实现二维码图片的生成",tags = "实现二维码图片的生成")
@Controller
public class QRCodeController {
    @Resource
    private QRcodeService qrcodeService;

    //这是之前不加base64编码的接收参数的值 因为无法接收 这里虽然写了 但是弃用了
    @GetMapping("/api/qrcode/showqrcode.do")
    public void showImg(String msg, HttpServletResponse response) throws IOException {
        BufferedImage image = QRCodeUtil.createColor(msg, 500);
        ImageIO.write(image, "png", response.getOutputStream());

    }

    @GetMapping("/api/qrcode/cardqrcode.do")
    public void  createQrcode(String msg,HttpServletResponse response){
        qrcodeService.createQrcode(msg, response);

    }


}
